package com.zhuo.project.k3.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.k3.domain.ZzDepot;
import com.zhuo.project.k3.mapper.ZzDepotMapper;
import com.zhuo.project.k3.service.IZzDepotService;

/**
 * 仓库信息Service业务层处理
 *
 * @author ruoyi
 * @date 2020-03-18
 */
@Service
public class ZzDepotServiceImpl implements IZzDepotService {
    @Autowired
    private ZzDepotMapper zzDepotMapper;

    /**
     * 查询仓库信息
     *
     * @param id 仓库信息ID
     * @return 仓库信息
     */
    @Override
    public ZzDepot selectZzDepotById(Long id) {
        return zzDepotMapper.selectZzDepotById(id);
    }

    @Override
    public ZzDepot selectZzDepotByDepotCode(String depotCode) {
        ZzDepot zzDepot = new ZzDepot();
        zzDepot.setFnumber(depotCode);
        List<ZzDepot> list = zzDepotMapper.selectZzDepotList(zzDepot);
        return list.get(0);
    }

    /**
     * 查询仓库信息列表
     *
     * @param zzDepot 仓库信息
     * @return 仓库信息
     */
    @Override
    public List<ZzDepot> selectZzDepotList(ZzDepot zzDepot) {
        return zzDepotMapper.selectZzDepotList(zzDepot);
    }

    /**
     * 新增仓库信息
     *
     * @param zzDepot 仓库信息
     * @return 结果
     */
    @Override
    public int insertZzDepot(ZzDepot zzDepot) {
        ZzDepot filter = new ZzDepot();
        filter.setFnumber(zzDepot.getFnumber());
        List<ZzDepot> filterList = zzDepotMapper.selectZzDepotList(filter);
        if (null != filterList && filterList.size() > 0) {
            Long id = filterList.get(0).getId();
            zzDepot.setId(id);
            zzDepot.setUpdateBy(SecurityUtils.getUsername());
            zzDepot.setUpdateTime(new Date());
            return zzDepotMapper.updateZzDepot(zzDepot);
        }
        zzDepot.setCreateBy(SecurityUtils.getUsername());
        zzDepot.setCreateTime(new Date());
        return zzDepotMapper.insertZzDepot(zzDepot);
    }

    /**
     * 修改仓库信息
     *
     * @param zzDepot 仓库信息
     * @return 结果
     */
    @Override
    public int updateZzDepot(ZzDepot zzDepot) {
        return zzDepotMapper.updateZzDepot(zzDepot);
    }

    /**
     * 批量删除仓库信息
     *
     * @param ids 需要删除的仓库信息ID
     * @return 结果
     */
    @Override
    public int deleteZzDepotByIds(Long[] ids) {
        return zzDepotMapper.deleteZzDepotByIds(ids);
    }

    /**
     * 删除仓库信息信息
     *
     * @param id 仓库信息ID
     * @return 结果
     */
    @Override
    public int deleteZzDepotById(Long id) {
        return zzDepotMapper.deleteZzDepotById(id);
    }
}
